package com.doge.walknovel.api.model

import android.content.Context
import com.doge.walknovel.business.WebActivity
import com.doge.walknovel.business.novel.NovelDetailActivity
import com.doge.walknovel.business.home.profile.topup.TopUpActivity
import com.doge.walknovel.business.home.profile.topup.TopUpRefer
import com.doge.walknovel.business.novel.NovelRefer

data class BannerInfo(
    val id: Int,
    val url: String?, // 展示封面
    val linkUrl: String?, //
    val name: String?,
    val startTime: Long?,
    val endTime: Long?,
    val jumpType: Int? // 0或者null 表示打开web. 1表示打开小说.linkUrl为novelId. 2表示打开TopUp
) {
    val isActivating: Boolean
        get() {
            val current = System.currentTimeMillis()
            return current >= (startTime ?: 0L) && current <= (endTime ?: 0L)
        }
}

fun BannerInfo?.process(context: Context?) {
    when (this?.jumpType) {
        1 -> NovelDetailActivity.start(context, this.linkUrl?.toIntOrNull(), NovelRefer.discoverBanner, id)
        2 -> TopUpActivity.start(context, TopUpRefer.banner)
        else -> WebActivity.start(context, this?.linkUrl)
    }
}